const Koa = require('koa');
const _static = require('koa-static');
const body = require('koa-better-body')
const session = require('koa-session');
var mysql = require('mysql');
var pool = mysql.createPool({
	connectionLimit: 10,
	host: 'example.org',
	user: 'bob',
	password: 'secret',
	database: 'my_db'
});

let db=co(pool)

const app = new Koa();

app.listen(9999);

app.use(body({
	uploadDir: './static/upload'
}))
app.use(session({
	maxAge: 20 * 60 * 1000, // 有效期
	renew: false //自动续期
}, app))
// 路由部分
app.use(require('./routes/index'));

// 静态资源
app.use(_static('./static', {
	maxage: 1000 * 60 * 30
}))
app.context.db=db;
 
app.keys = ['qwfasdvfasdfsda', 'asdfa4vsdfrsaw']
